package org.jeecg.modules.flow.callback.delivery.move;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import lombok.RequiredArgsConstructor;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.business.third.entity.EmsOrDmsDeliveryDto;
import org.jeecg.modules.business.third.service.IEmsOrDmsDeliveryOperateService;
import org.jeecg.modules.business.transfer.entity.WmsMoveReceipt;
import org.jeecg.modules.business.transfer.service.IWmsMoveReceiptService;
import org.jeecg.modules.flow.callback.enums.DocumentStatusEnum;
import org.jeecg.modules.flow.sys.common.BaseCustomBeanRun;
import org.jeecg.modules.flow.sys.entity.dto.BaseFlowDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 条料调拨因入移库单 通知配送
 *
 * @author gongwenkai
 * @version 1.0.0
 * @since 2023-11-27
 */
@RequiredArgsConstructor
@Component
public class Y103MoveReceiptNoticeDeliveryBean<T> extends BaseCustomBeanRun<T> {


    private final IWmsMoveReceiptService wmsMoveReceiptService;

    private final IEmsOrDmsDeliveryOperateService emsOrDmsDeliveryOperateService;

    @Override
    public void actureRun() {
        BaseFlowDto baseFlowDto = this.getBaseFlowDto();
        String receiptId = baseFlowDto.getInfoId();
        // 主动调用MDS发送移库请求
        EmsOrDmsDeliveryDto emsOrDmsDeliveryDto =new EmsOrDmsDeliveryDto();
        emsOrDmsDeliveryDto.setReceiptId(receiptId);
        emsOrDmsDeliveryDto.setTaskOrReciptType(2);
        emsOrDmsDeliveryDto.setType(0);
        emsOrDmsDeliveryOperateService.move(emsOrDmsDeliveryDto);
        wmsMoveReceiptService.update(new LambdaUpdateWrapper<WmsMoveReceipt>()
                .set(WmsMoveReceipt::getDocumentStatus, DocumentStatusEnum.PROCESS.getCode())
                .eq(WmsMoveReceipt::getId, receiptId)
        );
        baseFlowDto.setInfoId(receiptId);
        baseFlowDto.setResult(Result.OK());
    }
}
